package com.getpebble.android.framework.endpoint;

import com.getpebble.android.bluetooth.protocol.ProtocolMessage;
import com.getpebble.android.common.core.trace.Analytics.RemoteDeviceInterface;
import com.getpebble.android.common.core.trace.Trace;
import com.getpebble.android.common.model.FrameworkState;
import com.getpebble.android.framework.endpoint.EndpointRequest.EndpointAction;
import com.getpebble.android.framework.protocol.EndpointId;
import com.getpebble.android.framework.protocol.outbound.PblSetTimeMessage;
import com.google.common.collect.ImmutableSet;
import com.sun.mail.smtp.SMTPMessage;
import java.util.Set;

public class TimeControlEndpoint extends RequestableEndpoint {
    private static final String TAG = TimeControlEndpoint.class.getSimpleName();
    private IEndpointMessageSender mMessageSender;

    static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] $SwitchMap$com$getpebble$android$framework$endpoint$EndpointRequest$EndpointAction = new int[EndpointAction.values().length];

        static {
            try {
                $SwitchMap$com$getpebble$android$framework$endpoint$EndpointRequest$EndpointAction[EndpointAction.SEND_SET_TIME_MESSAGE.ordinal()] = 1;
            } catch (NoSuchFieldError e) {
            }
        }
    }

    public TimeControlEndpoint(IEndpointMessageSender messageSender) {
        if (messageSender == null) {
            throw new IllegalArgumentException("'messageSender' cannot be null!");
        }
        this.mMessageSender = messageSender;
    }

    private boolean sendSetTimeMessage() throws IllegalArgumentException {
        Trace.debug(TAG, "Sending set time message");
        RemoteDeviceInterface.logRemoteDeviceTimeSync();
        return this.mMessageSender.sendMessage(new PblSetTimeMessage());
    }

    Set<EndpointId> getSupportedEndpoints() {
        return ImmutableSet.of(EndpointId.TIME);
    }

    boolean onReceive(ProtocolMessage message) {
        Trace.error(TAG, "Received unexpected Get Time request from Pebble; should validate the message");
        return sendSetTimeMessage();
    }

    boolean onRequest(EndpointRequest request, FrameworkState frameworkState) {
        Trace.debug(TAG, "Got request");
        switch (AnonymousClass1.$SwitchMap$com$getpebble$android$framework$endpoint$EndpointRequest$EndpointAction[request.getAction().ordinal()]) {
            case SMTPMessage.RETURN_FULL /*1*/:
                Trace.debug(TAG, "Send set time message");
                sendSetTimeMessage();
                return true;
            default:
                Trace.debug(TAG, "No matching request found in TimeControlEndpoint, not handling.");
                return false;
        }
    }

    boolean onPrfRequest(EndpointRequest request, FrameworkState frameworkState) {
        Trace.debug(TAG, "Got request");
        return true;
    }
}
